<template>
    <!-- 用来存放之前其他app的页面连接 -->
    <iframe class="app-page-iframe" :id="id" :name="id" :src="iframeHref"></iframe>
</template>

<script lang="ts">
import { randomChar } from '@/utils/index';
import { Dialog } from 'vant';
export default {
    props: {
        href: {
            type: String,
            default: '#'
        },
    },
    computed: {
        iframeHref(): string {
            return this.href;
        },
    },
    data() {
        return {
            id: '',
        }
    },
    methods: {
        setAndroidPrefixObject() {
            try {
                if ((document.querySelector(`#${this.id}`) as any)?.contentWindow?.androidJS) {
                    return;
                }
                (document.querySelector(`#${this.id}`) as any).contentWindow.androidJS = (window as any)?.androidJS;
            } catch (e) {
                Dialog({
                    message:
                        '设置依赖参数失败，当前页面仅供android使用，请使用特定的android设备使用。如果继续使用将会有部分功能不能使用！'
                })
            }
        }
    },
    created() {
        this.id = `iframe_${randomChar(16)}`;
        setTimeout(() => {
            this.setAndroidPrefixObject();
        }, 1000);
    }
}
</script>

<style lang="scss" scoped>
.app-page-iframe {
    height: 100%;
    width: 100%;
    box-sizing: border-box;
    border: 0px;
}
</style>